package leetcode;

public class Lc35 {

    public int searchInsert(int[] nums, int target) {
        return binarySeearch(nums, target, 0, nums.length - 1);
    }

    public int binarySeearch(int[] nums, int target, int l, int r) {
        if (l == r) {
            if (nums[l] == target || nums[l] > target) {
                return l;
            }else {
                return l + 1;
            }
        }
        int mid = (l + r) >> 1;
        if (nums[mid] < target)
            return binarySeearch(nums, target, mid + 1, r);
        return binarySeearch(nums, target, l, mid);
    }


}
